package com.sunmouse.toolkit.fragment.camera;


import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sunmouse.toollib.adapter.BasicRecyclerAdapter;
import com.sunmouse.toolkit.R;
import com.sunmouse.toolkit.adapter.FunAdapter;
import com.sunmouse.toolkit.bean.PageBean;
import com.sunmouse.toolkit.fragment.BaseFragment;
import com.sunmouse.toolkit.util.PageUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class CameraFragment extends BaseFragment {


    @BindView(R.id.m_list)
    RecyclerView mList;
    Unbinder unbinder;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_list, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void init() {
        mData = new ArrayList<>();
        mAdapter = new FunAdapter(mData, getActivity());
        this.mList.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        this.mList.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new ItemClick());
        loadingData(1);
    }

    @Override
    public void loadingData(int page) {
        this.mData.add(new PageBean(PageUtil.Index.CAMERA_DEMO, "demo"));
        this.mData.add(new PageBean(PageUtil.Index.CAMERA2, "camera2"));
        this.mData.add(new PageBean(PageUtil.Index.CAMERA3, "camera3"));
        this.mAdapter.notifyDataSetChanged();
    }

    /**
     * item click
     */
    class ItemClick implements BasicRecyclerAdapter.OnItemClickListener {

        @Override
        public void onItemClick(int position) {
            int index = mData.get(position).getId();
            jump(index);

        }
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
